package com.ruoyi.project.mall.service.impl;


import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.common.utils.bootdo.UuidUtil;
import com.ruoyi.project.mall.dao.MallInvoiceApplyDao;
import com.ruoyi.project.mall.domain.MallInvoiceApplyDO;
import com.ruoyi.project.mall.service.MallInvoiceApplyService;
import com.ruoyi.project.wx.dao.OrderOrderDao;
import com.ruoyi.project.wx.domain.OrderOrderDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class MallInvoiceApplyServiceImpl implements MallInvoiceApplyService {
	@Autowired
	private MallInvoiceApplyDao mallInvoiceApplyDao;
	@Autowired
	private OrderOrderDao orderOrderDao;
	
	@Override
	public MallInvoiceApplyDO get(String id){
		return mallInvoiceApplyDao.get(id);
	}
	
	@Override
	public List<MallInvoiceApplyDO> list(Map<String, Object> map){
		return mallInvoiceApplyDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return mallInvoiceApplyDao.count(map);
	}
	
	@Override
	public int save(MallInvoiceApplyDO mallInvoiceApply){
		return mallInvoiceApplyDao.save(mallInvoiceApply);
	}
	
	@Override
	public int update(MallInvoiceApplyDO mallInvoiceApply){
		return mallInvoiceApplyDao.update(mallInvoiceApply);
	}
	
	@Override
	public int remove(String id){
		return mallInvoiceApplyDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return mallInvoiceApplyDao.batchRemove(ids);
	}

    @Override
    public List<MallInvoiceApplyDO> likeList(Map<String, Object> map){
        return mallInvoiceApplyDao.likeList(map);
    }
    @Override
    public int likeListCount(Map<String, Object> map){
        return mallInvoiceApplyDao.likeListCount(map);
    }

    @Override
    public R getInvoiceSpec(Map<String, Object> paramMap) {
		Map<String,Object> map =mallInvoiceApplyDao.getInvoiceSpec(paramMap);
		return R.ok().put("data",map);

    }

	@Override
	public R updateInvoiceApply(Map<String, Object> paramMap) {
		OrderOrderDO orderOrderDO = orderOrderDao.get(paramMap.get("orderId").toString());
		orderOrderDO.setSee(1);
		MallInvoiceApplyDO mallInvoiceApplyDO = new MallInvoiceApplyDO();
		mallInvoiceApplyDO.setDelFalg(0);
		mallInvoiceApplyDO.setId(UuidUtil.get32UUID());
		mallInvoiceApplyDO.setCaAt(new Date());
		mallInvoiceApplyDO.setUserId(paramMap.get("userId").toString());
		mallInvoiceApplyDO.setOrderId(paramMap.get("orderId").toString());
		mallInvoiceApplyDO.setInvoiceId(paramMap.get("invoiceId").toString());
		mallInvoiceApplyDao.save(mallInvoiceApplyDO);
		orderOrderDao.update(orderOrderDO);
		return R.ok();

	}



}
